<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>个人资料</title>
    <script th:src="@{/common/js/jquery.min.js}" type="text/javascript"></script>
    <script th:src="@{/common/layui/layui.js}" type="text/javascript"></script>
    <script th:src="@{/common/layui/layui.all.js}" type="text/javascript"></script>
    <script th:src="@{/common/js/userServer.js}" type="text/javascript"></script>
    <link rel="stylesheet" th:href="@{/common/layui/css/layui.css}">
</head>
<body>
<div>
    <form class="layui-form" action="" style="padding-top: 50px">
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <h2>个人信息</h2>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名：</label>
            <div class="layui-input-inline">
                <input type="text" id="uname" required lay-verify="required" placeholder="暂无信息"
                       autocomplete="off" class="layui-input" disabled="disabled" >
            </div>
            <button type="button" class="layui-btn layui-btn-normal" onclick="upUname();">名称修改</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码：</label>
            <div class="layui-input-inline">
                <input type="password" id="password" required lay-verify="required" placeholder="*******"
                       autocomplete="off" class="layui-input" disabled="disabled" >
            </div>
            <button type="button" class="layui-btn layui-btn-normal" onclick="upPassword()">密码修改</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户姓名：</label>
            <div class="layui-input-inline">
                <input type="text" id="xm" required lay-verify="required" placeholder="暂无信息"
                       autocomplete="off" class="layui-input" disabled="disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系方式：</label>
            <div class="layui-input-inline">
                <input type="text" id="phone" required lay-verify="required" placeholder="暂无信息"
                       autocomplete="off" class="layui-input" disabled="disabled" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址：</label>
            <div class="layui-input-inline">
                <input type="text" id="dizhi" required lay-verify="required" placeholder="暂无信息"
                       autocomplete="off" class="layui-input" disabled="disabled" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户类型：</label>
            <div class="layui-input-inline">
                <input type="text" name="utype" required lay-verify="required" placeholder="暂无信息"
                       autocomplete="off" class="layui-input" disabled="disabled" th:value="${utype}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">我的拍品数量：</label>
            <div class="layui-input-inline">
                <input type="number" name="myShopping" required lay-verify="required" placeholder="0"
                       autocomplete="off" class="layui-input" disabled="disabled" th:value="${myshoping}">
            </div>
            <button type="button" class="layui-btn" onclick="addCommodity();">上传拍品</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">竞拍成功次数：</label>
            <div class="layui-input-inline">
                <input type="number" name="auctionSuccess" required lay-verify="required" placeholder="0"
                       autocomplete="off" class="layui-input" disabled="disabled" th:value="${auctionSuccess}">
            </div>
            <label class="layui-form-label">竞拍失败次数：</label>
            <div class="layui-input-inline">
                <input type="number" name="auctionFail" required lay-verify="required" placeholder="0"
                       autocomplete="off" class="layui-input" disabled="disabled" th:value="${auctionFail}">
            </div>
        </div>
    </form>
</div>
<script th:inline="javascript">
    var uid;
    var passwoed;
    $(function () {
        var session = [[${session.user}]];
        $("#uname").val(session.uname);
        $("#password").val(session.password);
        $("#xm").val(session.xingming);
        $("#phone").val(session.iphone);
        $("#dizhi").val(session.dizhi);
        uid = session.uid;
    });
    //Demo
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });

    function addCommodity() {
        window.open(Base.serverPath+"/page/addCommodity.do")
    }
    function upUname() {
        layer.open({
            area: ['50%', '65%'],
            type: 1,
            content: '<div class="layui-form-item" style="text-align: center"><h3 style="margin-top: 20px;">用户名修改</h3> </div>' +
                '<div class="layui-form-item" style="margin-top: 20px">\n' +
                '            <label class="layui-form-label">用户名：</label>\n' +
                '            <div class="layui-input-inline">\n' +
                '                <input type="text" id="upname" required lay-verify="required" placeholder="请输入用户名"\n' +
                '                       autocomplete="off" class="layui-input">\n' +
                '            </div>\n' +
                '        </div>' +
                '<div class="layui-form-item" style="text-align: center"><button type="button" class="layui-btn layui-btn-normal" onclick="putUname();">修改</button></div>\n',
        });
    }

    function upPassword() {
        layer.open({
            area: ['50%', '75%'],
            type: 1,
            content: '<div class="layui-form-item" style="text-align: center"><h3 style="margin-top: 20px;">用户密码修改</h3> </div>' +
                '<div class="layui-form-item" style="margin-top: 20px">\n' +
                '            <label class="layui-form-label">原密码：</label>\n' +
                '            <div class="layui-input-inline">\n' +
                '                <input type="password" id="upassword" required lay-verify="required" placeholder="请输入原密码"\n' +
                '                       autocomplete="off" class="layui-input">\n' +
                '            </div>\n' +
                '        </div>' +
                '<div class="layui-form-item" style="margin-top: 20px">\n' +
                '            <label class="layui-form-label">新密码：</label>\n' +
                '            <div class="layui-input-inline">\n' +
                '                <input type="password" id="newpassword" required lay-verify="required" placeholder="请输入原密码"\n' +
                '                       autocomplete="off" class="layui-input">\n' +
                '            </div>\n' +
                '        </div>' +
                '<div class="layui-form-item" style="margin-top: 20px">\n' +
                '            <label class="layui-form-label">再次输入密码：</label>\n' +
                '            <div class="layui-input-inline">\n' +
                '                <input type="password" id="newpassword2" required lay-verify="required" placeholder="请输入原密码"\n' +
                '                       autocomplete="off" class="layui-input">\n' +
                '            </div>\n' +
                '        </div>' +
                '<div class="layui-form-item" style="text-align: center"><button type="button" class="layui-btn layui-btn-normal" onclick="putNewpassword();">提交</button></div>\n',

        });
    }

    function putUname() {
        var uname = $("#upname").val();
        console.log(uname)
        layer.confirm('确认修改', {icon: 3, title:'提示'}, function(index){
            var param = {};
            param.uname = uname;
            param.uid = uid;
            Base.requestServer("upUState",param,function (data) {
                if(data==1){
                    layer.msg("修改成功");
                }else {
                    layer.msg("修改失败");
                }
            },true);
        });
    }

    function putNewpassword() {
        var upassword = $("#upassword").val();
        var newpwd = $("#newpassword").val();
        var newpwd2 = $("#newpassword2").val();
        if(!upassword){
            layer.msg("请输入原始密码");
            return;
        }
        if(!newpwd){
            layer.msg("请输入新密码");
            return;
        }
        if(!newpwd2){
            layer.msg("请输入确定密码");
            return;
        }
        var password = [[${ppp}]];
        if(upassword==password) {
            if(newpwd!=newpwd2){layer.msg("密码不一致");return;}
            layer.confirm('确认修改', {icon: 3, title: '提示'}, function (index) {
                var param = {};
                param.password = newpwd;
                param.uid = uid;
                Base.requestServer("upUState", param, function (data) {
                    if (data == 1) {
                        layer.msg("修改成功");
                    } else {
                        layer.msg("修改失败");
                    }
                },true);
            });
        }else {
            layer.msg("密码错误")
        }
    }
</script>
</body>
</html>